import React, { Component } from 'react'
import axios from "axios"
export class Login extends Component {
  constructor(props) {
    super(props)
  
    this.state = {
      value1:'',
      pwd:''
    }
  }
 
  render() {
    const {value1,pwd}=this.state
    const tologin=()=>{
      let user={
        value1,
        pwd
      }
      axios.get("/login",{
        params:{
         value1:value1,
         pwd:pwd
        }
      }).then((res)=>{
        console.log(this)
        if(res.data.code===200){
          localStorage.setItem("user",JSON.stringify(user))
          this.props.history.go(-1)
          console.log(res.data.msg)
        }else{
          console.log(res.data.msg)
        }
      })
    }
    return (
      <div>
        <input type="text" value={value1} onChange={
          (e)=>{
           this.setState({
             value1:e.target.value

           })
          }
        }   />
        <input type="text" value={pwd}  onChange={
          (e)=>{
           this.setState({
            pwd:e.target.value

           })
          }
        } />
        <button onClick={    
            tologin
        }>登录</button>
      </div>
    )
  }
}

export default Login